home *** CD-ROM | disk | FTP | other *** search
- Path: charm.il.ft.hse.nl!not-for-mail
- From: robert@il.ft.hse.nl (robert)
- Newsgroups: comp.lang.c
- Subject: Re: using pipe() and dup2??????
- Date: 29 Feb 1996 10:41:14 +0100
- Organization: LSD...melts in your mind, not in your hand
- Message-ID: <4h3sbq$n35@charm.il.ft.hse.nl>
- References: <4h21f7$osc@maltese.eag.unisysgsg.com>
- NNTP-Posting-Host: charm.il.ft.hse.nl
-
- ssadra@maltese.eag.unisysgsg.com (Daniel R. Ascheman):
- >I am writing a program that uses grep to search for a password
- >to cross reference......I have only heard about pipe() being used
- >to manipulate to output of grep to a char buf[256] in my code instead
- >of out putting greps output to STDOUT i.e. a file in my dir.
-
- You should try popen(), which works much easier:
-
- FILE *fp;
- ...
- if ((fp = popen("grep ....", "r") == NULL)
- error();
- ...
-
- After this, you can use fp with most file-stream functions (fread(), fgets(),
- fclose()). However, since a pipe only be one of read/write (hence the "r"),
- you can either read-only or write-only using fp.
-
- Also, since popen() uses /bin/sh to execute the command, it will support
- things like tilde-expansion.
-
- Perhaps you could take a look at the manpage if things aren't clear
- enough.
-
- robert
-
-